package com.qst.rongxiaoserver.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qst.rongxiaoserver.mapper.QuestionMapper;
import com.qst.rongxiaoserver.model.QuestionModel;
import com.qst.rongxiaoserver.model.dto.QuestionDto;
import com.qst.rongxiaoserver.service.IQuestionService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

@Service
public class QuestionServiveImpl extends ServiceImpl<QuestionMapper,QuestionModel> implements IQuestionService {

    @Override
    public Boolean addQuestion(QuestionDto question) {

        QuestionModel questionModel = new QuestionModel();
        questionModel.setStatus(0);
        BeanUtils.copyProperties(question,questionModel);

        return save(questionModel);
    }

    @Override
    public Boolean updateQuestion(QuestionDto question) {
        QuestionModel questionModel = new QuestionModel();
        BeanUtils.copyProperties(question,questionModel);
        return updateById(questionModel);
    }

    @Override
    public Page<QuestionModel> getQuestionByPage(int pageNum, int pageSize) {
        Page<QuestionModel> page = new Page<>(pageNum, pageSize);
        return this.page(page);
    }
}
